/**
 * Created by dengyuntao on 2017/8/7.
 */
window.onload=function() {
  //  change("title", "input", "mainContent", "onclick");
    change("sec_title", "input", "sec_Content", "onclick");
    function change(title, title_list, mainContent, event) {
        var title = document.getElementById(title); //左侧导航部分
        var title_list = title.getElementsByTagName(title_list);
        var mainContent = document.getElementById(mainContent); //右侧详细，展示预约的详细二级项目
        var mainContent_list = mainContent.children;
        var len = title_list.length;
        var i = 0;
        for (i = 0; i < len; i++) {
            title_list[i].index = i;
            title_list[i][event] = function () {
                for (i = 0; i < len; i++) {
                    removeClass(title_list[i],"act");
                    addClass(mainContent_list[i],"hide");
                }
                addClass(title_list[this.index],"act");
                addClass(title_list[this.index],"sameBg");
                removeClass(mainContent_list[this.index],"hide");
                addClass(mainContent_list[this.index],"sameBg");
                console.log(mainContent_list[this.index].className);
            }
        }
    }
    var details=document.getElementById('details');
    details['onclick']=function(){
        var content=document.getElementById('mainContent');
        var order=document.getElementById('orders');
        var reserve=document.getElementById('reserve');
        var result=document.getElementById('result');
        var buy=document.getElementById('buy');
        addClass(content,"hide");
        removeClass(order,'hide');
        addClass(reserve,"hide");
        removeClass(result,'hide');
        addClass(details,"hide");
        removeClass(buy,'hide');
    };
    function hasClass(obj, cls) {
        return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
    }

    function addClass(obj, cls) {
        if (!hasClass(obj, cls)) {
            obj.className += " " + cls;
        }
    }

    function removeClass(obj, cls) {
        if (hasClass(obj, cls)) {
            var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
            obj.className = obj.className.replace(reg, ' ');
        }
    }

    function toggleClass(obj,cls){
        if(hasClass(obj,cls)){
            removeClass(obj, cls);
        } else {
            addClass(obj, cls);
        }
    }
};
